let mixinList = require('../../common/mixinList')
Page({
    behaviors: [mixinList],
    data: {
        tab_active: 0,
        reqUrl: '/supplier/order/index',
        tabs: [{ title: '待发货' }, { title: '待收货' }, { title: '已完成' }, { title: '已取消' }],
        scrollTop: 0,
        usePrivateMethod: true
    },
    onLoad: function(options) {
        const active = options.active
        if (active != undefined) this.setData({ tab_active: Number(active) })
        this.getList(true)
    },
    getParamsData() { //页面特殊的请求参数，需要时在页面内覆盖此方法，默认返回{}
        return { type: this.data.tab_active + 1, limit: 4 }
    },
    privateMethod(refresh, res) {
        return new Promise(resolve => {
            res.data.forEach(order => {
                order.order_product.forEach(item => {
                    item.product_img = item.product_img + '!img_200'
                })
            })

            resolve(res.data)
        })
    },
    onTabChange(event) {
        this.setData({
            empty: true,
            list: [],
            tab_active: event.detail.index,
            scrollTop: 0
        })
        this.getList(true)
    },
    toDetail(e) {
        const { index } = e.detail
        wx.navigateTo({
            url: `/pages/order_detail/index?order_id=${this.data.list[index].order_id}`
        })
    }
})